package view.subscriberpanels;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.HashSet;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import prefuse.data.query.RangeQueryBinding;

import view.ViewManager;
import view.util.ViewUtil;
import view.visualizations.DateZoomVis;
import data.DataManager;

/**
 * A panel for navigation. Interacting with this panel will change "level" of the
 * main view.
 */
public class NavigationPane extends VisSubscriber {
	
	private void setupView() {
		JLabel titleLabel = (JLabel) ViewUtil.createLabelWithAlignment("Navigation", CENTER_ALIGNMENT);
		titleLabel.setFont(new Font(this.getFont().getName(), Font.BOLD, this.getFont().getSize()+2));
		this.add(titleLabel);
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
	}
	
	private void addBackButton() {
		JButton back = new JButton("Go Back");
		back.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				ViewManager.goBack();
			}
		});
		this.add(back);
	}
	
	public void showOverallView() {
		this.removeAll();
		setupView();
		
//		HashSet<Object> dates = DataManager.getInstance().getUniqueColumnEntries("Date");
//		final JList dateList = new JList(dates.toArray());
//		
//		dateList.addListSelectionListener(new ListSelectionListener() {
//			
//			@Override
//			public void valueChanged(final ListSelectionEvent e) {
//				Date selected = (Date)dateList.getSelectedValue();
//				RangeQueryBinding dateQ = ViewManager.getCurrentVis().getDateQuery();
//				dateQ.createSlider().setValue(dateQ.getObjectModel().getIndex(selected));
//				
////				ViewManager.setCurrentVis(new DateZoomVis(selected));
//			}
//		});
//		
//		JScrollPane dateScrollPane = new JScrollPane(dateList);
//		dateScrollPane.setPreferredSize(new Dimension(180, 200));
//		dateScrollPane.setMaximumSize(new Dimension(180, 200));
//		this.add(dateScrollPane);
	}
	
	@Override
	void showDateZoomView() {
		this.removeAll();
		setupView();
		addBackButton();
	}
	@Override
	void showMeetZoomView() {
		this.removeAll();
		setupView();
		addBackButton();
	}
	@Override
	void showTableView() {
		this.removeAll();
		setupView();
		addBackButton();
	}
	@Override
	void updateView() {
		
	}

}
